/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef NET_TCPDISPATCHER_H_
#define NET_TCPDISPATCHER_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <string>
#include <event2/event.h>
#include <event2/bufferevent.h>
#include <UGame/Macros.h>
#include <UGame/Base/AtomicValue.h>

namespace UGame {
namespace Net {
	class TcpClient;

	class TcpDispatcher
	{
	public:
		TcpDispatcher(void);
		~TcpDispatcher(void);

		bool Open(void);
		void Close(void);

		struct event_base* AcquireBase(void) {
			++_load;
			return _base;
		}
		void ReleaseBase(void) { --_load; }

		void Update(void);
	private:
		struct event_base* _base;
		UGame::AtomicValue_UInt32 _load;
		DISALLOW_COPY_AND_ASSIGN(TcpDispatcher);
	};

}}

#endif // NET_TCPDISPATCHER_H_
